var startingPage;
var number = 10;
var orderState = 5;

//初始数据
function loadWebList() {
    startingPage = 0;
    var data = {
        "page": startingPage,
        "number": number,
        "orderState": orderState
    };
    $.ajax({
        url: "findOrderByOrderList",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {

            } else {
                for (var i = 0; i < data.order_List.length; i++) {
                    if (data.order_List[i].orderState == 5) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td>" + data.order_List[i].orderName + "</td>\n" +
                            "                            <td>" + data.order_List[i].orderPrice + "</td>\n" +
                            "                            <td>" + data.order_List[i].orderDate + "</td>\n" +
                            "                            <td class=\"td-status\">\n" +
                            "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已下单</span>\n" +
                            "                            </td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                <a onclick=\"xadmin.open('订单详情','Background-OrderReturnEdit.html',600,400," + data.order_List[i].orderID + ")\"  href=\"javascript:;\" title=\"编辑\">\n" +
                            "                                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                            "                                </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>";
                    }
                }
            }
            $("#SellerData").html(code);
            $("#pageNumber").val(data.count);
            $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");

        }
    });
}

//上一页
function myProjectTable_previous() {
    startingPage = startingPage - 1;
    if (startingPage < 0) {
        startingPage = 0;
        Swal.fire("提示", "数据不存在", "warning");
    } else {
        var data = {
            "page": startingPage * number,
            "number": number,
            "orderState": orderState
        };
        $.ajax({
            url: "findOrderByOrderList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {

                } else {
                    for (var i = 0; i < data.order_List.length; i++) {
                        if (data.order_List[i].orderState == 5) {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.order_List[i].orderName + "</td>\n" +
                                "                            <td>" + data.order_List[i].orderPrice + "</td>\n" +
                                "                            <td>" + data.order_List[i].orderDate + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已下单</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"xadmin.open('订单详情','Background-OrderReturnEdit.html',600,400," + data.order_List[i].orderID + ")\"  href=\"javascript:;\" title=\"编辑\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>";
                        }
                    }
                }
                $("#SellerData").html(code);
                $("#pageNumber").val(data.count);
                $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");

            }
        });
    }
}

//下一页
function myProjectTable_next() {
    startingPage = startingPage + 1;
    var startingPageNumber = startingPage * number;
    var numberSum = $("#pageNumber").val();
    if (startingPageNumber > numberSum && (startingPageNumber - number) < numberSum) {
        startingPage = startingPage - 1;
        Swal.fire("提示", "数据浏览已到底", "warning");
    } else {
        var data = {
            "page": startingPageNumber,
            "number": number,
            "orderState": orderState
        };
        $.ajax({
            url: "findOrderByOrderList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {

                } else {
                    for (var i = 0; i < data.order_List.length; i++) {
                        if (data.order_List[i].orderState == 5) {
                            code += "  <tr>\n" +
                                "                            <td>" + (i + 1) + "</td>\n" +
                                "                            <td>" + data.order_List[i].orderName + "</td>\n" +
                                "                            <td>" + data.order_List[i].orderPrice + "</td>\n" +
                                "                            <td>" + data.order_List[i].orderDate + "</td>\n" +
                                "                            <td class=\"td-status\">\n" +
                                "                                <span class=\"layui-btn layui-btn-normal layui-btn-mini\">已下单</span>\n" +
                                "                            </td>\n" +
                                "                            <td class=\"td-manage\">\n" +
                                "                                <a onclick=\"xadmin.open('订单详情','Background-OrderReturnEdit.html',600,400," + data.order_List[i].orderID + ")\"  href=\"javascript:;\" title=\"编辑\">\n" +
                                "                                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                                "                                </a>\n" +
                                "                            </td>\n" +
                                "                        </tr>";
                        }
                    }
                }
                $("#SellerData").html(code);
                $("#pageNumber").val(data.count);
                $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");

            }
        });
    }
}

$(function () {
    loadWebList();
});